package banco.composEstoque;

import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;

import banco.Banco;
import dominio.composEstoque.CFOP;
import dominio.composEstoque.Deb_Cred;
import dominio.composEstoque.Demonstrativo;
import fachada.composEstoque.Fachada_CFOP;

public class CFOP_DAO implements Fachada_CFOP {

	/* (non-Javadoc)
	 * @see banco.composEstoque.Fachada_CFOP#selectAllCFOP()
	 */
	@SuppressWarnings("finally")
	public Collection selectAllCFOP() throws IOException {
		
		Connection conn = null;
	    PreparedStatement stmt = null;
	    ResultSet rs = null;
	    CFOP cfop;
	    Collection<CFOP> res = new ArrayList<CFOP>();
	    
	    try {
	        conn = Banco.getConexaoEXTRATOPAES();
	        stmt = conn.prepareStatement("select * from composestoque_cfop");
	        rs = stmt.executeQuery();
	        while (rs.next()){
	        	cfop = new CFOP();
	        	cfop.setCodigo(rs.getString("codigo"));
	        	cfop.setDebito_credito(Deb_Cred.setDeb_Cred(rs.getString("debito_credito")));
	        	cfop.setDemonstrativo(Demonstrativo.setDemonstrativo(rs.getString("demonstrativo")));
	        	res.add(cfop);
	        }
	    }
	    catch (SQLException ex) {
	        ex.printStackTrace();
	    }
	    finally {
	        Banco.closeConexao(conn, rs, stmt);
	        return res;
	    }
	    
	}
	
}
